package com.edu.whty.service.impl;


import com.edu.whty.common.tools.MapUtils;
import com.edu.whty.dao.ResShareDao;
import com.edu.whty.entity.base.PageList;
import com.edu.whty.entity.disk.ResOwner;
import com.edu.whty.entity.share.ResShare;
import com.edu.whty.service.ResShareService;
import net.sf.json.JSONObject;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.Consts;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Component("resShareService")
public class ResShareServiceImpl implements ResShareService {
	
	@Resource
	private ResShareDao resShareDao;
	

	


	@Override
	public void addResShare(ResShare resShare) throws Exception {
		 resShareDao.insertOne(resShare);
	}

	@Override
	public void addResShareBatch(List<ResShare> list) throws Exception {
		resShareDao.batchInsert(list);
	}

	@Override
	public ResShare getResShare(ResShare resShare) throws Exception {
		return resShareDao.selectOne(resShare);
	}

	@Override
	public List<ResShare> getResShareList(ResShare resShare) throws Exception {
		return resShareDao.selectList(resShare);
	}


	@Override
	public ResShare getResShareByUserid(String userid) throws Exception {
		return resShareDao.getResShareByUserid(userid);
	}

	@Override
	public PageList queryForPaginationBy7(String userId) throws Exception {
//		Map<String, Object> params = MapUtils.newHashMap();
//		//个人网盘7.0 查询分页总的页数
//		params.put("userId", userId);
//		params.put("curPage", page.getCurPage());
//		params.put("numPerPage", page.getNumPerPage());
//		params.put("curCount", page.getCurCount());
//		int count = resShareDao.countResShare(userId);
//		if (page == null) {
//			page = new Pagination();
//		}
//		page.setTotalCount(count);
//		List<ResShare> list = resShareDao.selectForPagination7(params);
//		PageList pageList = new PageList();
//		pageList.setList(list);
//		pageList.setPage(page);
		return null;
	}

	@Override
	public List<ResShare> queryByShortCode(String shortCode) {
		return resShareDao.selectByshortCode(shortCode);
	}

	@Override
	public List<ResShare> queryListByShareIds(String shareIds) throws Exception {
		List<ResShare> resShareList = new ArrayList();
		String []shareIdArray =	shareIds.split(",");
		for (String shareID : shareIdArray) {
			ResShare resShare = new ResShare();
			resShare.setShareId(shareID);
			resShareList.add(resShareDao.selectOne(resShare));
		}
		return resShareList;
	}

	@Override
	public List<ResOwner> selectPubShareByShortCode(String shortCode) {
		return resShareDao.selectResOwnerByShortCode(shortCode);
	}

	@Override
	public List<ResShare> queryListByResId(String resId) throws Exception {
		return resShareDao.selectByResid(resId);
	}

	@Override
	public void deleteResShare(ResShare resShare) throws Exception {
		resShareDao.deleteByShareId(resShare);
	}

}
